package com.ruoyi.point.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.point.pojo.Picker;
import com.ruoyi.point.service.IPickerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 抓手Controller
 *
 * @author ruoyi
 * @date 2024-04-26
 */
@RestController
@RequestMapping("/system/picker")
public class PickerController extends BaseController
{
    @Autowired
    private IPickerService pickerService;

    /**
     * 查询抓手列表
     */
    @PreAuthorize("@ss.hasPermi('system:picker:list')")
    @GetMapping("/list")
    public TableDataInfo list(Picker picker)
    {
        startPage();
        List<Picker> list = pickerService.selectPickerList(picker);
        return getDataTable(list);
    }

    /**
     * 导出抓手列表
     */
    @PreAuthorize("@ss.hasPermi('system:picker:export')")
    @Log(title = "抓手", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Picker picker)
    {
        List<Picker> list = pickerService.selectPickerList(picker);
        ExcelUtil<Picker> util = new ExcelUtil<Picker>(Picker.class);
        util.exportExcel(response, list, "抓手数据");
    }

    /**
     * 获取抓手详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:picker:query')")
    @GetMapping(value = "/{pickerId}")
    public AjaxResult getInfo(@PathVariable("pickerId") Long pickerId)
    {
        return success(pickerService.selectPickerByPickerId(pickerId));
    }

    /**
     * 新增抓手
     */
    @PreAuthorize("@ss.hasPermi('system:picker:add')")
    @Log(title = "抓手", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Picker picker)
    {
        return toAjax(pickerService.insertPicker(picker));
    }

    /**
     * 修改抓手
     */
    @PreAuthorize("@ss.hasPermi('system:picker:edit')")
    @Log(title = "抓手", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Picker picker)
    {
        return toAjax(pickerService.updatePicker(picker));
    }

    /**
     * 删除抓手
     */
    @PreAuthorize("@ss.hasPermi('system:picker:remove')")
    @Log(title = "抓手", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pickerIds}")
    public AjaxResult remove(@PathVariable Long[] pickerIds)
    {
        return toAjax(pickerService.deletePickerByPickerIds(pickerIds));
    }
}
